package com.sskj.level.http;


import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.lib.bean.PageBean;
import com.sskj.level.bean.PingCangType;
import com.sskj.level.bean.TradeInfoBean;
import com.sskj.level.bean.TradeListBean;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.SPUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.bean.StockCoinBean;
import com.sskj.lib.bean.SysConfigBean;
import com.sskj.lib.bean.WSFiveBean;

import java.util.List;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService implements IHttpService {

    @Override
    public PostRequest<HttpData<List<StockCoinBean>>> getProduct(String code) {
        return OkGo.<HttpData<List<StockCoinBean>>>post(HttpConfig.BASE_URL + HttpConfig.PRODUCT_LIST)
                .params("type", 4)
                .params("code", code)
                .params("coinArea", "1");
    }

    @Override
    public GetRequest<HttpData<TradeInfoBean>> getRisk() {
        return OkGo.<HttpData<TradeInfoBean>>get(HttpConfig.BASE_URL + HttpConfig.TRADE_INFO)
                .params("mobile", SPUtil.get(SPConfig.MOBILE, ""));
    }

    @Override
    public PostRequest<HttpData> levelAllPc(String id, String stockCode) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.LEVEL_ALL_PC)
                .params("id", id);
//                .params("stockCode", stockCode);
    }

    @Override
    public GetRequest<HttpData<PageBean<TradeListBean>>> getTradeList(String startDate, String endDate, String type, String code) {
        return OkGo.<HttpData<PageBean<TradeListBean>>>get(HttpConfig.BASE_URL + HttpConfig.TRADE_POSITION_LIST)
                .params("startDate", startDate)
                .params("endDate", endDate)
                .params("stockCode", code)
                .params("type", type);
    }

    @Override
    public GetRequest<HttpData<PageBean<TradeListBean>>> getTradeList(String type, String code) {
        return OkGo.<HttpData<PageBean<TradeListBean>>>get(HttpConfig.BASE_URL + HttpConfig.TRADE_POSITION_LIST)
                .params("stockCode", code)
                .params("type", type);
    }

    @Override
    public PostRequest<HttpData<WSFiveBean>> getPankou(String code) {
        return OkGo.<HttpData<WSFiveBean>>post(HttpConfig.BASE_URL + HttpConfig.COIN_PANKOU_LIST)
                .params("code", code);
    }

    @Override
    public PostRequest<HttpData> createOrder(String entrustLot, String buyPrice, String buyBillType, String stockCode, String billPriceType, String stopProfit, String stopLoss, String lever) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.TRADE_LEVEL_CREATE)
//                .params("id", SPUtil.get(SPConfig.ID, ""))
                .params("lever", lever)
                .params("entrustLot", entrustLot)
                .params("buyPrice", buyPrice)
                .params("stockCode", stockCode)
                .params("billPriceType", billPriceType)
                .params("buyBillType", buyBillType)
                .params("stopProPrice", stopProfit)
                .params("stopLossPrice", stopLoss)
                .params("stopProfit", stopProfit)
                .params("stopLoss", stopLoss);
    }

    @Override
    public PostRequest<HttpData<List<SysConfigBean>>> getSysConf(String type) {

        return OkGo.<HttpData<List<SysConfigBean>>>post(HttpConfig.BASE_URL + HttpConfig.SYS_CONFIG)
                .params("type", type);
    }

    @Override
    public PostRequest<HttpData> pingCang(String orderId) {

        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.PINGCANG)
                .params("orderId", orderId);
    }

    @Override
    public PostRequest<HttpData> cancelOrder(String orderId) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.CANCEL_ORDER)
                .params("orderId", orderId);
    }

    @Override
    public PostRequest<HttpData> setStop(String orderId, String stopProfitPrice, String stopLossPrice) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SET_STOP)
                .params("id", orderId)
                .params("stopProfitPrice", stopProfitPrice)
                .params("stopLossPrice", stopLossPrice);
    }

    @Override
    public GetRequest<HttpData<List<PingCangType>>> getPingCangType() {
        return OkGo.<HttpData<List<PingCangType>>>get(HttpConfig.BASE_URL + HttpConfig.PINGCANG_TYPE);

    }
}